from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-02 14:13:04.095597
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 02, Sep, 2021
Time: 14:13:08
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.9432
Nobs: 402.000 HQIC: -46.4836
Log likelihood: 4370.70 FPE: 4.55618e-21
AIC: -46.8379 Det(Omega_mle): 3.65225e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.431031 0.094411 4.565 0.000
L1.Burgenland 0.102853 0.048746 2.110 0.035
L1.Kärnten -0.115421 0.024226 -4.764 0.000
L1.Niederösterreich 0.164403 0.105010 1.566 0.117
L1.Oberösterreich 0.132378 0.102941 1.286 0.198
L1.Salzburg 0.283195 0.051119 5.540 0.000
L1.Steiermark 0.022412 0.067712 0.331 0.741
L1.Tirol 0.109899 0.053504 2.054 0.040
L1.Vorarlberg -0.115831 0.048262 -2.400 0.016
L1.Wien -0.007776 0.093179 -0.083 0.933
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.012496 0.219189 0.057 0.955
L1.Burgenland -0.048870 0.113170 -0.432 0.666
L1.Kärnten 0.036762 0.056245 0.654 0.513
L1.Niederösterreich -0.197699 0.243796 -0.811 0.417
L1.Oberösterreich 0.505284 0.238992 2.114 0.034
L1.Salzburg 0.307816 0.118679 2.594 0.009
L1.Steiermark 0.105168 0.157204 0.669 0.504
L1.Tirol 0.315586 0.124217 2.541 0.011
L1.Vorarlberg -0.009060 0.112048 -0.081 0.936
L1.Wien -0.016086 0.216328 -0.074 0.941
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.255414 0.047992 5.322 0.000
L1.Burgenland 0.087924 0.024779 3.548 0.000
L1.Kärnten -0.003211 0.012315 -0.261 0.794
L1.Niederösterreich 0.206014 0.053379 3.859 0.000
L1.Oberösterreich 0.173649 0.052328 3.319 0.001
L1.Salzburg 0.036095 0.025985 1.389 0.165
L1.Steiermark 0.016941 0.034420 0.492 0.623
L1.Tirol 0.063804 0.027198 2.346 0.019
L1.Vorarlberg 0.058411 0.024533 2.381 0.017
L1.Wien 0.106202 0.047365 2.242 0.025
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181039 0.046945 3.856 0.000
L1.Burgenland 0.047134 0.024238 1.945 0.052
L1.Kärnten -0.007410 0.012046 -0.615 0.538
L1.Niederösterreich 0.135806 0.052215 2.601 0.009
L1.Oberösterreich 0.321343 0.051186 6.278 0.000
L1.Salzburg 0.098812 0.025418 3.887 0.000
L1.Steiermark 0.132811 0.033669 3.945 0.000
L1.Tirol 0.076835 0.026604 2.888 0.004
L1.Vorarlberg 0.054526 0.023998 2.272 0.023
L1.Wien -0.041364 0.046332 -0.893 0.372
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212038 0.093530 2.267 0.023
L1.Burgenland -0.059209 0.048291 -1.226 0.220
L1.Kärnten -0.035338 0.024000 -1.472 0.141
L1.Niederösterreich 0.109691 0.104031 1.054 0.292
L1.Oberösterreich 0.179881 0.101980 1.764 0.078
L1.Salzburg 0.258200 0.050642 5.099 0.000
L1.Steiermark 0.081333 0.067081 1.212 0.225
L1.Tirol 0.122080 0.053005 2.303 0.021
L1.Vorarlberg 0.112076 0.047812 2.344 0.019
L1.Wien 0.023379 0.092310 0.253 0.800
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025828 0.072730 0.355 0.723
L1.Burgenland 0.025878 0.037551 0.689 0.491
L1.Kärnten 0.052044 0.018663 2.789 0.005
L1.Niederösterreich 0.212776 0.080895 2.630 0.009
L1.Oberösterreich 0.335835 0.079301 4.235 0.000
L1.Salzburg 0.045018 0.039380 1.143 0.253
L1.Steiermark -0.003627 0.052162 -0.070 0.945
L1.Tirol 0.113780 0.041217 2.761 0.006
L1.Vorarlberg 0.063876 0.037179 1.718 0.086
L1.Wien 0.129533 0.071781 1.805 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186699 0.088536 2.109 0.035
L1.Burgenland 0.020273 0.045712 0.443 0.657
L1.Kärnten -0.059422 0.022719 -2.616 0.009
L1.Niederösterreich -0.125831 0.098475 -1.278 0.201
L1.Oberösterreich 0.198716 0.096534 2.058 0.040
L1.Salzburg 0.026826 0.047937 0.560 0.576
L1.Steiermark 0.301661 0.063498 4.751 0.000
L1.Tirol 0.490773 0.050174 9.781 0.000
L1.Vorarlberg 0.068627 0.045259 1.516 0.129
L1.Wien -0.105439 0.087380 -1.207 0.228
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158331 0.096572 1.640 0.101
L1.Burgenland -0.006153 0.049861 -0.123 0.902
L1.Kärnten 0.062837 0.024781 2.536 0.011
L1.Niederösterreich 0.201703 0.107414 1.878 0.060
L1.Oberösterreich -0.129373 0.105297 -1.229 0.219
L1.Salzburg 0.240781 0.052289 4.605 0.000
L1.Steiermark 0.153225 0.069262 2.212 0.027
L1.Tirol 0.052283 0.054729 0.955 0.339
L1.Vorarlberg 0.124423 0.049367 2.520 0.012
L1.Wien 0.145057 0.095312 1.522 0.128
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488739 0.052316 9.342 0.000
L1.Burgenland -0.011061 0.027012 -0.409 0.682
L1.Kärnten -0.010704 0.013425 -0.797 0.425
L1.Niederösterreich 0.204354 0.058190 3.512 0.000
L1.Oberösterreich 0.258540 0.057043 4.532 0.000
L1.Salzburg 0.022989 0.028327 0.812 0.417
L1.Steiermark -0.023884 0.037522 -0.637 0.524
L1.Tirol 0.070611 0.029648 2.382 0.017
L1.Vorarlberg 0.057756 0.026744 2.160 0.031
L1.Wien -0.054429 0.051634 -1.054 0.292
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.017821 0.076146 0.132960 0.131834 0.040736 0.067638 0.001743 0.174404
Kärnten 0.017821 1.000000 -0.047262 0.125415 0.045295 0.069929 0.456723 -0.093136 0.091375
Niederösterreich 0.076146 -0.047262 1.000000 0.282524 0.082693 0.271814 0.020032 0.148074 0.252381
Oberösterreich 0.132960 0.125415 0.282524 1.000000 0.182501 0.288366 0.154438 0.109297 0.135691
Salzburg 0.131834 0.045295 0.082693 0.182501 1.000000 0.129440 0.057589 0.104326 0.050406
Steiermark 0.040736 0.069929 0.271814 0.288366 0.129440 1.000000 0.130420 0.087689 -0.026829
Tirol 0.067638 0.456723 0.020032 0.154438 0.057589 0.130420 1.000000 0.041213 0.116782
Vorarlberg 0.001743 -0.093136 0.148074 0.109297 0.104326 0.087689 0.041213 1.000000 -0.045236
Wien 0.174404 0.091375 0.252381 0.135691 0.050406 -0.026829 0.116782 -0.045236 1.000000